package com.kk.permission;

import android.content.Context;

import com.kk.permission.adapter.PermissionAdapter;
import com.kk.permission.adapter.PermissionAdapter.IPermissionAdapter;
import com.kk.permission.utils.callershow.PrefUtil;

public class PermissionWrapper {
    private static PermissionWrapper sInstance;
    private Context sContext;

    private class DialerPermissionAdapter implements IPermissionAdapter {
        public boolean buildConfigIsEmbeddedInRom() {
            return false;
        }

        public void onFinishOpenPermissions() {
        }

        private DialerPermissionAdapter() {
        }

        public int prefUtilGetKeyInt(String str, int i) {
            return PrefUtil.getKeyInt(str, i);
        }

        public int prefUtilGetKeyIntRes(String str, int i) {
            return PrefUtil.getKeyIntRes(str, i);
        }

        public boolean prefUtilGetKeyBoolean(String str, boolean z) {
            return PrefUtil.getKeyBoolean(str, z);
        }

        public boolean prefUtilGetKeyBooleanRes(String str, int i) {
            return PrefUtil.getKeyBooleanRes(str, i);
        }

        public String prefUtilGetKeyString(String str, String str2) {
            return PrefUtil.getKeyString(str, str2);
        }

        public String prefUtilGetKeyStringRes(String str, int i) {
            return PrefUtil.getKeyStringRes(str, i);
        }

        public long prefUtilGetKeyLong(String str, long j) {
            return PrefUtil.getKeyLong(str, j);
        }

        public float prefUtilGetKeyFloat(String str, float f) {
            return PrefUtil.getKeyFloat(str, f);
        }

        public void prefUtilSetKey(String str, int i) {
            PrefUtil.setKey(str, i);
        }

        public void prefUtilSetKey(String str, boolean z) {
            PrefUtil.setKey(str, z);
        }

        @Override
        public String touchLifeControllerGetExperimentResult(String str) {
            return "";
        }

        public void prefUtilSetKey(String str, String str2) {
            PrefUtil.setKey(str, str2);
        }

        public void prefUtilSetKey(String str, long j) {
            PrefUtil.setKey(str, j);
        }

        public void prefUtilSetKey(String str, float f) {
            PrefUtil.setKey(str, f);
        }

        public void prefUtilDeleteKey(String str) {
            PrefUtil.deleteKey(str);
        }

        public boolean prefUtilContainsKey(String str) {
            return PrefUtil.containsKey(str);
        }

//        public Typeface skinGetTypeface(String str) {
//            if ("icon1".equalsIgnoreCase(str)) {
//                return TouchPalTypeface.ICON1;
//            }
//            if ("icon2".equalsIgnoreCase(str)) {
//                return TouchPalTypeface.ICON2;
//            }
//            if ("icon3".equalsIgnoreCase(str)) {
//                return TouchPalTypeface.ICON3;
//            }
//            if ("icon4".equalsIgnoreCase(str)) {
//                return TouchPalTypeface.ICON4;
//            }
//            if ("icon1_v6".equalsIgnoreCase(str)) {
//                return TouchPalTypeface.ICON1_V6;
//            }
//            if ("icon2_v6".equalsIgnoreCase(str)) {
//                return TouchPalTypeface.ICON2_V6;
//            }
//            if ("icon3_v6".equalsIgnoreCase(str)) {
//                return TouchPalTypeface.ICON3_V6;
//            }
//            return "icon4_v6".equalsIgnoreCase(str) ? TouchPalTypeface.ICON4_V6 : null;
//        }

//        public String touchLifeControllerGetExperimentResult(String str) {
//            return Controller.getInst().getResult(str);
//        }

        public Context getAppContext() {
            return sContext;
        }
    }

    public void init(Context context) {
        sContext = context;
        PermissionAdapter.init(new DialerPermissionAdapter());
    }

    public static PermissionWrapper getInst() {
        if (sInstance == null) {
            synchronized (PermissionWrapper.class) {
                if (sInstance == null) {
                    sInstance = new PermissionWrapper();
                }
            }
        }
        return sInstance;
    }

    private BaseExternalImpl externalImpl = new BaseExternalImpl();

    public static class BaseExternalImpl {
        public boolean isDefaultDialer() {
            return false;
        }
        public boolean isNotifiAccessEnabled() {
            return false;
        }

        public void reportEvent(String key, String value){

        }

        public void reportEvent(String key){

        }
    }

    public void registerExternalImpl(BaseExternalImpl newImpl) {
        externalImpl = newImpl;
    }

    boolean isDefaultDialer() {
        if (externalImpl != null)
            return externalImpl.isDefaultDialer();
        return false;
    }

    boolean isNotifiAccessEnabled() {
        if (externalImpl != null)
            return externalImpl.isNotifiAccessEnabled();
        return false;
    }


    public void reportEvent(String key, String value){
        if (externalImpl != null)
            externalImpl.reportEvent(key, value);
    }

    public void reportEvent(String key){
        if (externalImpl != null)
            externalImpl.reportEvent(key);
    }

}